﻿<%@ page language="C#" autoeventwireup="true" codefile="content.aspx.cs" inherits="main_content"
title="Content" masterpagefile="~/template/base/template_base.master" %>
<%@ mastertype virtualpath="~/template/base/template_base.master" %>
<%@ register src="~/template/base/templatewrap_form1_begin.ascx" tagname="begin" tagprefix="templatewrap_form1" %>
<%@ register src="~/template/base/templatewrap_form1_end.ascx" tagname="end" tagprefix="templatewrap_form1" %>
<%@ register src="~/form/content.ascx" tagname="content" tagprefix="form" %>
<%@ reference control="~/main/content_feed.ascx"%>
<asp:content id="Content1" contentplaceholderid="HtmlHead" runat="server">
<asp:placeholder id="plhClientScript" runat="server" visible="false" enableviewstate="false">
	<script type="text/javascript">
	//<![CDATA[
function classContentCrud(idRegion, strEditorContentCssUrl, strEditorTemplateJavascriptUrl) {
	var memberPublic = this;
	memberPublic.init = init;
	memberPublic.onEdit = onEdit;
	memberPublic.idRegion = idRegion;
	memberPublic.strEditorContentCssUrl = strEditorContentCssUrl;
	memberPublic.strEditorTemplateJavascriptUrl = strEditorTemplateJavascriptUrl;
	var _eleRegion, _elePageType;

	// Edit mode.
	function onEdit(eleTrigger, idPanelOutput, idPanelEdit, idUser) {
		// Get page data.
		var intPageType = parseInt($('#ajax-page-type', _eleRegion).html()[0], 10);
		var elePageTitle = $('#ajax-page-title > *', _eleRegion).get(0);
		
		// Get containers.
		var elePanelOutput = $('#' + idPanelOutput, _eleRegion).get(0);
		var elePanelEdit = $('#' + idPanelEdit, _eleRegion).get(0);
		
		// Get content from output.
		var elePanelOutput_ContentId = $('.ajax-content-id', elePanelOutput).get(0);
		var elePanelOutput_ContentTitle = $('.ajax-content-title', elePanelOutput).get(0);
		var elePanelOutput_ContentBody = $('.ajax-content-body-inner', elePanelOutput).get(0);
		var elePanelOutput_ContentOrder = $('.ajax-content-order', elePanelOutput).get(0);
		var elePanelEdit_ContentTitle = $('.ajax-content-title', elePanelEdit).get(0);
		var elePanelEdit_ContentBody = $('.ajax-content-body', elePanelEdit).get(0);
		var elePanelEdit_ContentOrder = $('.ajax-content-order', elePanelEdit).get(0);

		// Create text editor.
		var clsTextEditorEdit_ContentBody = new classTextEditor(idRegion, elePanelEdit_ContentBody.id, strEditorContentCssUrl, strEditorTemplateJavascriptUrl);
		clsTextEditorEdit_ContentBody.init();
		
		// Set content to input.
		$(elePanelEdit_ContentTitle).val($(elePanelOutput_ContentTitle).html());
		$(elePanelEdit_ContentBody).val(clsTextEditorEdit_ContentBody.encodeHtml($(elePanelOutput_ContentBody).html()));
		$(elePanelEdit_ContentOrder).val($(elePanelOutput_ContentOrder).html());
		
		// Toggle between two panels.
		_togglePanels(elePanelOutput, elePanelEdit);
	
		// Set events.
		$('.ajax-content-btncancel', elePanelEdit).unbind().bind('click', function(e) {
			// Toggle between two panels.
			_togglePanels(elePanelEdit, elePanelOutput, function() {
				// Unload text editor.
				clsTextEditorEdit_ContentBody.unloadTextEditor();
			});
		});
		$('.ajax-content-btnokay', elePanelEdit).unbind().bind('click', function(e) {
			// Create data interchange format.
			var jsonObject = {
				"intContentId":parseInt($(elePanelOutput_ContentId).html(), 10),
				"intUserId":parseInt(idUser, 10),
				"strTitle":$(elePanelEdit_ContentTitle).val(),
				"strBody":clsTextEditorEdit_ContentBody.encodeHtml(clsTextEditorEdit_ContentBody.getContent()),
				"intOrder":parseInt($(elePanelEdit_ContentOrder, 10).val(), 10)
			};
			var jsonString = YAHOO.lang.JSON.stringify(jsonObject);
			// Perform AJAX.
			jsonAjaxWebservice('contents', 'setContent', jsonString, null, function(status, data) {
				if(status == 'success' && data == true) {
					// Set data to output.
					if(intPageType == 1) {
						var indexTitle = window.document.title.indexOf('::');
						window.document.title = jsonObject.strTitle + window.document.title.substring(indexTitle - 1);
						$(elePageTitle).html(jsonObject.strTitle);
					}
					$(elePanelOutput_ContentTitle).html(jsonObject.strTitle);
					$(elePanelOutput_ContentBody).html(clsTextEditorEdit_ContentBody.decodeHtml(jsonObject.strBody));
					$(elePanelOutput_ContentOrder).text(jsonObject.intOverrideOrder);
					// Toggle between two panels.
					_togglePanels(elePanelEdit, elePanelOutput, function() {
						// Unload text editor.
						clsTextEditorEdit_ContentBody.unloadTextEditor();
					});
				} else {
					console.log(status);
					console.log(data);
				}
			});
		});
	}
	// Toggle between two panels.
	function _togglePanels(eleHide, eleShow, fnCallback) {
		$(eleHide).fadeOut('normal', function() {$(eleShow).fadeIn('normal', function() {
			// Require for browser Microsoft Internet Explorer 7.
			if($.browser.msie) {this.style.removeAttribute('filter');}
			// Callback function.
			if(jQuery.isFunction(fnCallback)) {fnCallback.call(this);}
		});});
	}
	// Init this class.
	function init() {
		_eleRegion = $('#' + idRegion).get(0);
	}
}
	//]]>
	</script>
</asp:placeholder>
<asp:placeholder id="plhJavaScriptTextEditor" runat="server" visible="false">
	<script src="<%#ResolveClientUrl("~/js/tiny_mce/tiny_mce.js")%>" type="text/javascript"></script>
	<script src="<%#ResolveClientUrl("~/js/diehard_text_editor.js")%>" type="text/javascript"></script>
</asp:placeholder>
<asp:placeholder id="plhJavaScriptCrud" runat="server" visible="false">
	<script type="text/javascript">
	//<![CDATA[
var clsThis = new classContentCrud('region-middle', '<%#ResolveClientUrl("~/css/content/document.css")%>', '<%#ResolveClientUrl("~/js/javascript_template.aspx")%>');
$(document).ready(function() {clsThis.init();});
	//]]>
	</script>
</asp:placeholder>
<asp:placeholder id="plhJavaScriptAdd" runat="server" visible="false">
	<script type="text/javascript">
	//<![CDATA[
var clsThis = new classTextEditor('region-middle', '<%=ucContent.prop_txtBody.ClientID%>', '<%#ResolveClientUrl("~/css/content/document.css")%>', '<%#ResolveClientUrl("~/js/javascript_template.aspx")%>');
$(document).ready(function() {clsThis.init();});
	//]]>
	</script>
</asp:placeholder>
<asp:placeholder id="plhJavaScriptEdit" runat="server" visible="false">
	<script type="text/javascript">
	//<![CDATA[
var clsThis = new classTextEditor('region-middle', '<%=ucContent.prop_txtBody.ClientID%>', '<%#ResolveClientUrl("~/css/content/document.css")%>', '<%#ResolveClientUrl("~/js/javascript_template.aspx")%>');
$(document).ready(function() {clsThis.init();});
	//]]>
	</script>
</asp:placeholder>
<asp:placeholder id="plhPageStyle" runat="server" visible="false"/>
</asp:content>
<asp:content id="Content4" contentplaceholderid="RegionMiddle" runat="server">
<asp:placeholder id="plhCrud" runat="server" visible="false">
	<asp:panel id="pnlPageControlPanel" cssclass="frmpage-controlpanel" visible="false" runat="server">
		<asp:label id="lblControlPanelPrepend" runat="server"/><br/><asp:label id="lblControlPanelAppend" runat="server"/><asp:linkbutton id="lnkContentAdd" runat="server" oncommand="lnkContentAdd_Command" commandname="add" commandargument="" causesvalidation="false" visible="false">Add</asp:linkbutton><asp:linkbutton id="lnkContentEditSpecial" runat="server" onclick="lnkContentEditSpecial_Click" causesvalidation="false" visible="false">Advanced Edit</asp:linkbutton>
	</asp:panel>
	<h3 id="ajax-page-title"><asp:hyperlink id="hypPageTitle" runat="server"/></h3>
	<asp:repeater id="rptrContent" runat="server" enableviewstate="false" onitemdatabound="rptrContent_ItemDataBound" onitemcommand="rptrContent_ItemCommand"><itemtemplate>
	<asp:panel id="pnlOutput" cssclass="main-content" runat="server">
		<h4 class="title" id="hgcContentTitle" runat="server"><asp:hyperlink id="hypContentTitle" cssclass="ajax-content-title" runat="server"/></h4>
		<div class="status"><asp:label id="lblContentStatus" runat="server"/></div>
		<div class="body"><asp:label id="lblContentBody" cssclass="ajax-content-body" runat="server"/></div>
		<asp:panel id="pnlContentControlPanel" cssclass="frmpost-controlpanel" visible="false" runat="server">
			<div class="right"><asp:hyperlink id="hypEdit" runat="server">Edit</asp:hyperlink></div>
			<asp:label id="lblContentId" runat="server"/> | <asp:label id="lblContentType" runat="server"/> | <asp:label id="lblOrder" runat="server"/> | <asp:label id="lblAuthorUserId" runat="server"/> | <asp:label id="lblEditorUserId" runat="server"/>
		</asp:panel>
	</asp:panel>
	<asp:panel id="pnlEdit" runat="server" visible="false" style="display:none;">
		<templatewrap_form1:begin runat="server"/>
		<div class="frmcommon">
			<form:content id="ucContent_Ajax" runat="server" visible="true"/>
			<br/>
			<div class="footer center">
				<input type="button" class="btnokay ajax-content-btnokay" value="OK"/> <input type="button" class="btncancel ajax-content-btncancel" value="Cancel"/>
			</div>
		</div>
		<templatewrap_form1:end runat="server"/>
	</asp:panel>
	</itemtemplate></asp:repeater>
</asp:placeholder>
<asp:placeholder id="plhAdd" runat="server" visible="false">
	<h3>Add Post</h3>
	<p>All fields are required to add an item.</p>
	<templatewrap_form1:begin runat="server"/>
	<div class="frmcommon">
		<form:content id="ucContent" runat="server" visible="true"/>
		<div class="footer">
			<asp:button id="btnAddOkay" runat="server" text="OK" cssclass="btnokay" onclick="btnAddOkay_Click"/> <asp:button id="btnAddCancel" runat="server" text="Cancel" cssclass="btncancel" causesvalidation="false" onclick="btnAddCancel_Click"/>
		</div>
	</div>
	<templatewrap_form1:end runat="server"/>
</asp:placeholder>
<asp:label id="lblError" runat="server" cssclass="error"/>
<asp:label id="lblLog" runat="server" cssclass="log"/>
</asp:content>